/**
 * 
 */
package exo2;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;


/**
 * 
 * @author fcamps
 *
 *
 *
 * javac -d destDir Hello.java Server.java Client.java
 * 
 * 
 * 
 * For example, on the Solaris(tm) Operating System:

rmiregistry &

By default, the registry runs on TCP port 1099. To start a registry on a different port, specify the port number from the command line. 

If the registry will be running on a port other than 1099, you'll need to specify the port number in the calls to LocateRegistry.getRegistry in the Server and Client classes. For example, if the registry is running on port 2001 in this example, the call to getRegistry in the server would be:

Registry registry = LocateRegistry.getRegistry(2001);

Start the server
To start the server, run the Server class using the java command as follows:

On the Solaris Operating System:

java -classpath classDir -Djava.rmi.server.codebase=file:classDir/ example.hello.Server &

where classDir is the root directory of the class file tree (see destDir in the section "Compiling the source files"). Setting the java.rmi.server.codebase system property ensures that the registry can load the remote interface definition (note that the trailing slash is important); for more information about using this property, see the codebase tutorial.

The output from the server should look like this:

Server ready
The server remains running until the process is terminated by the user (typically by killing the process).

Run the client
Once the server is ready, the client can be run as follows:

java  -classpath classDir example.hello.Client
where classDir is the root directory of the class file tree (see destDir in the section "Compiling the source files").


 * 
 * 
 *
 */


public class Client {

    private Client() {}

    public static void main(String[] args) {

        String host = (args.length < 1) ? null : args[0];
        try {
            Registry registry = LocateRegistry.getRegistry(host);
            Hello stub = (Hello) registry.lookup("Hello");
            String response = stub.sayHello();
            System.out.println("response: " + response);
        } catch (Exception e) {
            System.err.println("Client exception: " + e.toString());
            e.printStackTrace();
        }
    }
}